package com.changgou.goods.controller;
import com.changgou.entity.PageResult;
import com.changgou.entity.Result;
import com.changgou.entity.StatusCode;
import com.changgou.goods.service.BrandService;
import com.changgou.goods.pojo.Brand;
import com.github.pagehelper.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;
@RestController
@CrossOrigin
@RequestMapping("/brand")
public class BrandController {


    @Autowired
    private BrandService brandService;


    /**
     * 品牌分页条件查询
     */
    @GetMapping(value = "/search/{page}/{size}")
    public Result findPage(@RequestParam Map searchMap,@PathVariable("page")int page,@PathVariable("size") int size){
        Page pageInfo = brandService.findPage(searchMap, page, size);
        PageResult pageResult = new PageResult(pageInfo.getTotal(),pageInfo.getResult());
        return new Result(true,StatusCode.OK,"查询成功",pageResult);
    }

    /**
     * 商品品牌下拉显示
     * 穿的ID是第三级的ID
     */
    @PostMapping("data/{id}")
    public Result dataList(@PathVariable int id){
        List<Brand> brandList = brandService.findBrand(id);
        return new Result(true, StatusCode.OK,"查询成功",brandList);

    }

    @GetMapping("")
    public Result getBrand(){
        return null;
    }
    /**
     * 新增品牌接口
     * @param brand
     * @return
     */
    @PostMapping(value = "/add")
    public Result add(@RequestBody Brand brand){
        brandService.add(brand);
        return new Result(true,StatusCode.OK,"新增成功");
    }

    @DeleteMapping("/{id}")
    public Result delById(@PathVariable("id") Integer id){
        brandService.delById(id);
        return new  Result(true,StatusCode.OK,"删除成功");
    }
}
